package com.flannery.learningandroid.data.kotlin

open class Person(var name: String, var age: Int) {
    // 基类
    open fun study() {}
}

// 子类有构造函数
class Student(name: String, age: Int, var no: String, var score: Int) : Person(name, age) {

}

fun testMain1() {
    val s = Student("1name", 18, "123445", 89);
    println("学生名： ${s.name}")
    println("年龄： ${s.age}")
    println("学生号： ${s.no}")
    println("成绩： ${s.score}")
}

//子类没有构造函数
class Student2 : Person {
    constructor(ctx: String) : super(ctx, 0) {
    }

    constructor(ctx: String, attrs: Int) : super(ctx, attrs) {
    }

    //重写父类的study函数
    override fun study() {
        super.study()
    }
}

//多个继承
open class A {
    open val x: Int get() = 0

    open fun f() {
        print("A")
    }

    fun a() {
        print("a")
    }
}

interface B {

    val count: Int
    fun f() {
        print("B")
    } //接口的成员变量默认是 open 的

    fun b() {
        print("b")
    }
}

class C() : A(), B {
    override val count: Int = 0
    override val x: Int = 1

    override fun f() {
        super<A>.f()//调用 A.f()
        super<B>.f()//调用 B.f()
    }
}

class C2(override val count: Int) : B //只有interface可以这么做

fun main(args: Array<String>) {
    val c = C()
    c.f() //AB
    println(c.x) //1
}

